package com.happyscan138.makefun.base;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

import static com.loopj.android.http.AsyncHttpClient.log;


/**
 * Created by Administrator on 2017/5/9.
 */



    public class ProcessImageView extends ImageView {
        // 进度值
        int process = 25;
        // 控件宽高
        private int w;
        private int h;

        public ProcessImageView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
        }

        public ProcessImageView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            // TODO Auto-generated constructor stub
        }

        public ProcessImageView(Context context, AttributeSet attrs) {
            super(context, attrs);
            // TODO Auto-generated constructor stub
        }

        @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);
            w = getWidth();
            h = getHeight();
            Log.v("h", h + "");
            Paint paint = new Paint();
            // 设置画笔的argb
            paint.setARGB(200, 205, 197, 191);
            if (process < h) {
                // 绘制进度的阴影区域，随着process的增大 阴影区域减小
                canvas.drawRect(0, 0, w, h - process, paint);
                Paint tpaint = new Paint();
                tpaint.setTextSize(40);
                tpaint.setColor(Color.WHITE);
                // 绘制百分比
                canvas.drawText((int) (((float) process / h) * 100) + "%", w / 2
                        - getPaddingLeft() / 2, h / 2, tpaint);
            }
        }
        public void setProcess(int process) {
            log.e("progress",process+"");
            this.process = process;
            // 重绘
            postInvalidate();
        }
    }